﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Motorway_Simulator.Simulator;
using Motorway_Simulator.Components;
using System.Drawing;
using System.Drawing.Drawing2D;


namespace Motorway_Simulator.GUI.Simulator
{
    class SimulationCanvas : Panel
    {
        
        private Timer timer;
        private SimulationController simulatorController;
        
        private static Size size = new Size(3000, 3000);
        private Bitmap roadImage;
        public static Size Size1
        {
            get { return SimulationCanvas.size; }
            set { SimulationCanvas.size = value; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SimulationCanvas"/> class.
        /// </summary>
        /// <param name="simulatorController">The simulator controller.</param>
        public SimulationCanvas(SimulationController simulatorController)
            : base()
        {
            
            this.simulatorController = simulatorController;
            roadImage = simulatorController.DrawRoad(null);
            timer = new Timer();
            timer.Interval = 500;
            timer.Enabled = true;
            timer.Tick += new EventHandler(RepaintCanvas);
            timer.Start();
           
           // this.CreateGraphics().BeginContainer()

        }

        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.Paint"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"/> that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            if (simulatorController != null)
            {
                
                
               e.Graphics.DrawImage(roadImage,new Point(0,0));
                  simulatorController.DrawAllVehicles(e.Graphics);
            }
        }

        /// <summary>
        /// Repaints the canvas.
        /// </summary>
        /// <param name="o">The o.</param>
        /// <param name="ev">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public void RepaintCanvas(object o , EventArgs ev)
        {
            this.Invalidate();
            this.Update();



            
        }




        internal static Bitmap GetSize()
        {
            throw new NotImplementedException();
        }
    }
}
